<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
          name="viewport">
    <meta content="ie=edge" http-equiv="X-UA-Compatible">
    <title>TestAPI</title>
</head>
<body>
    <input id="message" type="text">
    <button id="submit">提交</button>
    
    <script>
        //创建 websocket实例
        let websocket=new WebSocket("ws://127.0.0.1:8083/test"); 
        //需要给实例挂载一些回调函数
        websocket.onopen=function(){
                console.log("连接建立");
        }
        websocket.onerror=function(){
            console.log("连接异常");
        }
        websocket.onclose=function(){
            console.log("连接关闭");
        }
        websocket.onmessage=function(e){
            console.log("收到消息："+e.data);
        }

        //实现点击按钮后，通过websocket发送请求
        let button=document.querySelector("#submit");
        let input=document.querySelector("#message");
        button.onclick=function(){
            console.log("发送消息："+input.value);
            websocket.send(input.value);
        }
    </script>
</body>
</html>